/**
 * 
 */
package edu.pku.sei.modeler.uml.commands.activity;

import edu.pku.sei.modeler.commands.ModelCommand;
import edu.pku.sei.modeler.model.core.MetaElement;
import edu.pku.sei.modeler.model.core.MetaModelElement;
import edu.pku.sei.modeler.model.uml.BasicActivities.ControlFlow;
import edu.pku.sei.modeler.model.uml.FundamentalActivities.ActivityNode;
import edu.pku.sei.modeler.uml.commands.ConnectionModelCreateCommand;

/**
 * @author YanYan
 *
 */
public class CreateControlFlowCommand extends ConnectionModelCreateCommand {
	private ActivityNode src,des;
	private ControlFlow controlFlow;
	public CreateControlFlowCommand(MetaModelElement connectionModel,
			MetaModelElement sourceModel) {
		super(connectionModel, sourceModel);
		src = (ActivityNode) sourceModel;
		controlFlow = (ControlFlow) connectionModel;
		
	}

	public void setTarget(MetaModelElement target){
		super.setTarget(target);
		des = (ActivityNode) target;
	}
	
	
	public boolean canExecute() {
		return true;
	}
	
	public void execute() {
		if(src != null){
			src.getOutgoing().add(controlFlow);
		}
		if(des != null) {
			des.getIncoming().add(controlFlow);
		}
		if(controlFlow != null){
			controlFlow.setContainer(src);
			controlFlow.setModel(src.getModel());
		}
	}
	
	public void undo() {
		//TODO
	}
}
